package tool

import (
	"bufio"
	"io/ioutil"
	"net/http"

	"golang.org/x/net/html/charset"
	"golang.org/x/text/transform"
)

func GetDecoder(resp *http.Response) string {

	// 统一转码
	// 获取解析的正确编码
	hdByte, _ := bufio.NewReader(resp.Body).Peek(1024)
	e, _, _ := charset.DetermineEncoding(hdByte, "")
	// 转码
	ioreader := transform.NewReader(resp.Body, e.NewDecoder())
	rt, _ := ioutil.ReadAll(ioreader)

	return rt
}
